package com.hornsun.data.dbo;

import com.hornsun.util.ObjByteUtil;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

/**
 * Created by zhouzhenyan on 2018/5/29.
 */
public class PacketData {
    public HeartBeatCode code;
    public int validTime;
    public int nConnectionCnt;
    public int nToken;

    public enum HeartBeatCode
    {
        hbcSuccess,             // 心跳正常
        hbcNotLogin,			// 未登录
        hbcNoRight,             // 无软件权限
        hbcUserError,            //账号或密码错
        hbcUnitialPwd,           //初始密码
        hbcExpired,             // 账号过期
        hbcReachLimit,			// 在限量达到上限
    };



    public static byte[] toBytesArray(PacketData packetData) {
        try {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            DataOutputStream outputStream = new DataOutputStream(stream);
            outputStream.writeInt(ObjByteUtil.BytesOrderConv(packetData.code.ordinal()));
            outputStream.writeInt(ObjByteUtil.BytesOrderConv(packetData.validTime));
            outputStream.writeInt(ObjByteUtil.BytesOrderConv(packetData.nConnectionCnt));
            outputStream.writeInt(ObjByteUtil.BytesOrderConv(packetData.nToken));
            return stream.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
